package com.jinmdz.fmis.api.admin.controller;

import com.jinmdz.fmis.api.admin.model.rolerelation.RoleMenuButtonRelationSaveData;
import com.jinmdz.fmis.api.admin.model.rolerelation.RoleMenuButtonRoleIdData;
import com.jinmdz.fmis.api.admin.model.rolerelation.RoleMenuTableData;
import com.jinmdz.fmis.api.admin.service.RoleRelationService;
import com.jinmdz.fmis.api.base.BaseController;
import com.jinmdz.fmis.core.base.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;

/**
 * 角色、菜单、按钮关联关系维护相关接口
 *
 * @author LiCongLu
 * @date 2020-03-19 11:25
 */
@Api(description = "角色、菜单、按钮关联关系维护相关接口")
@RestController()
@RequestMapping("/admin/role-menu-button-relation")
public class RoleMenuButtonRelationController extends BaseController {

    @Resource
    private RoleRelationService roleRelationService;

    /**
     * 根据角色id加载角色下包含的菜单数据和按钮数据
     *
     * @param data 角色主键
     * @return
     * @author LiCongLu
     * @date 2020-03-19 11:26
     */
    @ApiOperation(value = "根据角色id加载角色下包含的菜单数据和按钮数据", notes = "根据角色id加载角色下包含的菜单数据和按钮数据，关联表【role_menu_relation、menu_button_relation】，菜单表【business_system_menu】，菜单按钮表【business_system_menu_button】")
    @PostMapping("/load-role-menu-button-with-role-id")
    public BaseResult<ArrayList<RoleMenuTableData>> loadRoleMenuButtonWithRoleId(@RequestBody RoleMenuButtonRoleIdData data) {
        return resultHandler(userItem -> roleRelationService.loadRoleMenuButtonWithRoleId(data));
    }

    /**
     * 保存角色菜单按钮关联信息
     *
     * @author LiCongLu
     * @date 2020-03-19 11:29
     */
    @ApiOperation(value = "保存角色菜单按钮关联信息", notes = "保存角色菜单按钮关联信息到表【role_menu_relation、menu_button_relation】中")
    @PostMapping("/save-role-menu-button-relation")
    public BaseResult saveRoleMenuButtonRelation(@RequestBody RoleMenuButtonRelationSaveData data) {
        return resultHandler(data, userItem -> roleRelationService.saveRoleMenuButtonRelation(userItem, data));
    }
}
